<?php
namespace yan\editor_frontend\editorxml;
use yii\helpers\Html;
class WebLayoutWidget extends WebWidget{
	public function run(){
		if(empty($this->value['value'])) return null;

		// LayoutAsset::register($this->view);
		
		$options = $this->options;
		$shtml = Html::beginTag('div', $options);

		$num = !empty($this->value['value']['content']) ? $this->value['value']['content'] : $this->value['childs'][0];
		$inner = [];
		for ($i=0; $i < $num; $i++) {
			$inner_shtml = '<div class="col-xs-'.$this->getCol($num).'">';

			if(!empty($this->child[$i])){
				$inner_shtml .= $this->child[$i];
			}
			$inner_shtml .= '</div>';
			$inner[] = $inner_shtml;
		}
		$shtml .= Html::tag('div', implode("\n", $inner), ['class'=>'row']);
		$shtml .= Html::endTag('div');
		return $shtml;
	}
	protected function getCol($type){
		$arr = [
			'1'=>'col-12',
			'2'=>'col-6',
			'3'=>'col-4',
			'4'=>'col-3',
			'5'=>'col-25',
			'6'=>'col-2',
		];
		return isset($arr[$type]) ? $arr[$type] : $arr[1];
	}
}